package ge.telasi.tasks.ui.file;

import ge.telasi.tasks.ui.UIUtils;
import java.io.IOException;
import java.util.Properties;
import javax.swing.Icon;

/**
 * File decoration utilities.
 *
 * @author dimitri
 */
public class FileDecorationUtils {
    public static Properties FILE = new Properties();

    static {
        try {
            FILE.load(FileDecorationUtils.class.getResourceAsStream("file.properties"));
        } catch (IOException ioex) {}
    }

    public static String getExtension(String fileName) {
        int index = fileName.lastIndexOf(".");
        if (index != -1) {
            return fileName.substring(index + 1);
        }
        return null;
    }

    public static Icon getIcon(String ext) {
        String imgPath =null;
        if (ext != null) {
            imgPath = FILE.getProperty("f_" + ext.toLowerCase());
        }
        if (imgPath == null) {
            imgPath = "page.png";
        }
        return UIUtils.getIcon16x16(imgPath);
    }

    public static String getTypeDescription(String ext) {
        String typeName = null;
        if (ext != null) {
            typeName = FILE.getProperty("f_" + ext.toLowerCase() + "_name");
        }
        if (typeName == null) {
            typeName = "ფაილი";
        }
        return typeName;
    }

}
